Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmChat1
	Inherits System.Windows.Forms.Form
	Private Declare Function MessageBeep Lib "user32" (ByVal wType As Integer) As Integer
	Public Sub AddMessageToList(ByVal mess As String)
    Dim part As String = ""
		Dim possplit As Integer
    If chkActivate.CheckState = 1 Then Me.BringToFront()
		If chkBeep.CheckState = 1 Then MessageBeep(0)
		Do 
			If Len(part) > 0 Then part = "   "
			possplit = 70
			Do While Mid(mess, possplit, 1) <> " " And Len(mess) > 70 And possplit > 0
				possplit = possplit - 1
			Loop 
			If possplit < 2 Then possplit = 70
			part = part & VB.Left(mess, possplit)
			mess = Mid(mess, possplit + 1)
			List1.Items.Add(part)
		Loop While Len(mess) > 0
		List1.SelectedIndex = List1.Items.Count - 1
	End Sub
	
	Private Sub Text1_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles Text1.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
    'On Error Resume Next
		If KeyAscii = 13 And Trim(Text1.Text) <> "" Then
			KeyAscii = 0
			'If Form1.Connected Then
			AddMessageToList(Form1.NickName & "> " & Text1.Text)
			List1.SelectedIndex = List1.Items.Count - 1
      If Form1.SockClient.GetState = Winsock_Control.WinsockStates.Connected Then
        Form1.SockClient.Send("#010text_" & Text1.Text)
      End If
      Text1.Text = ""
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
End Class